/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 04.02.2006
 *
 *************************************************/
package fightplan.views.tables;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;

import com.jgoodies.forms.factories.Borders;

import fightplan.business.Category;
import fightplan.business.Winner;
import fightplan.core.Style;
import fightplan.ui.BeanListTableModel;
import fightplan.ui.BeanPropertyTableCellRenderer;

@SuppressWarnings("serial")
public class WinnerTable extends JPanel {
	private JTable table;
	private BeanListTableModel<Winner> tableModel;

	public WinnerTable() {
		super(new BorderLayout());
		this.setBorder(Borders.DIALOG_BORDER);

		tableModel = new BeanListTableModel<Winner>(null, new String[] { "rank", "fighterHolder.fighter",
				"fighterHolder.fighter.dojo" }, new String[] { "Rang", "Teilnehmer", "Dojo" });
		tableModel.setColumnReadOnly(0);
		tableModel.setColumnReadOnly(1);
		tableModel.setColumnReadOnly(2);
		table = new JTable(tableModel);
		TableColumnModel cm = table.getColumnModel();
		cm.getColumn(0).setMaxWidth(40);
		cm.getColumn(1).setCellRenderer(new BeanPropertyTableCellRenderer("name"));
		cm.getColumn(2).setCellRenderer(new BeanPropertyTableCellRenderer("name"));
		table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		JScrollPane scrollPane = new JScrollPane(table);
		scrollPane.setPreferredSize(new Dimension(5000, 5000));
		scrollPane.getViewport().setBackground(Style.UNUSED_TABLE_SPACE);
		add(scrollPane, BorderLayout.CENTER);
	}

	public void setCategory(Category category) {
		tableModel.setList(category.getPlan().getWinners());
	}

}
